#include "stdafx.h"
#include "Player_impl_Z.h"
#include <cassert>
#include <iostream>

#pragma comment(lib, "libzplay.lib")
Player_impl::Player_impl(){
    player_ = CreateZPlay();
}
Player_impl::~Player_impl(){
    player_->Release();
}

bool Player_impl::OpenFile(const std::wstring& file_name){
    return player_->OpenFileW(file_name.c_str(), sfAutodetect) != 0;
}

bool Player_impl::CloseFile(){
    return player_->Close() != 0;
}
bool Player_impl::Play(){
    return player_->Play() != 0;
}

bool Player_impl::PlayFromTo(long start_pos, long end_pos)
{
    TStreamTime start_time;
    start_time.ms = start_pos;

    TStreamTime end_time;
    end_time.ms = end_pos;
    
    return player_->PlayLoop(tfMillisecond, &start_time, tfMillisecond, &end_time, 1, 0) != 0;

}

long Player_impl::GetFileLength()
{
    TStreamInfoW info;
    player_->GetStreamInfoW(&info);
    return info.Length.hms.millisecond;
}
long Player_impl::GetCurrentPos()
{
    TStreamTime pos;
    player_->GetPosition(&pos);
    return pos.hms.millisecond;
}

bool Player_impl::PlayFrom(long pos)
{
    //TODO::
    return true;
}
bool Player_impl::Pause()
{
    //TODO::
    return true;
}
